//
//  LBHTTPClient.m
//  LvoeBeen_Imitation
//
//  Created by Mac on 17/2/18.
//  Copyright © 2017年 itcast. All rights reserved.
//

#import "LBHTTPClient.h"

@implementation LBHTTPClient

+ (instancetype) sharedClent {
    static LBHTTPClient *_instance;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        NSURL *baseUrl = [NSURL URLWithString:@"http://iosapi.itcast.cn/loveBeen/"];
        _instance = [[LBHTTPClient alloc] initWithBaseURL:baseUrl];
        
        _instance.requestSerializer = [[AFJSONRequestSerializer alloc] init];
        _instance.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    });
    return _instance;
}

+ (void)loadDataWithType:(HttpType)httpType urlString:(NSString *)urlString param:(NSDictionary *)param progressBlock:(void (^)(NSProgress *))progressBlock SuccedBlock:(void (^)(NSURLSessionDataTask *,id))succedBlock failureBlock:(void (^)(NSURLSessionDataTask *,NSError *))failureBlock {
    
    switch (httpType) {
        case HttpTypeGet:
            [[LBHTTPClient sharedClent] GET:urlString parameters:param progress:progressBlock success:succedBlock failure:failureBlock];
            break;
            
        case HttpTypePost:
            [[LBHTTPClient sharedClent] POST:urlString parameters:param progress:progressBlock success:succedBlock failure:failureBlock];
            break;
            
        default:
            break;
    }
}

@end
